package org.example.struct.array;

import com.alibaba.fastjson.JSON;

/**
 * @author liyishan
 * @date 2023/8/15 10:04
 * @apiNote
 */

public class Test00509Fib {
    public static void main(String[] args) {
        int n = 5;
        System.out.println(JSON.toJSON(test(n)));
    }

    public static int test(int n) {
        if (n < 2) {
            return n;
        }
        int p = 0, q = 0, r = 1;
        for (int i = 2; i <= n; ++i) {
            p = q;
            q = r;
            r = p + q;
        }
        return r;
    }
}
